package actions;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.sun.xml.internal.messaging.saaj.packaging.mime.util.BEncoderStream;

import bean.CreateUserFormBean;

public class CreateUserAction extends Action{

	@Override
	public String execute(HttpServletRequest request, HttpSession s) throws Exception {
		
		String nachname = "";
		String vorname 	= "";
		String username = "";
		String password = "";
		String role 	= "";
		
		try {
			nachname = new String(request.getParameter("nachname").getBytes("ISO-8859-1"),"UTF-8");
			vorname = new String(request.getParameter("vorname").getBytes("ISO-8859-1"),"UTF-8");
			username = new String(request.getParameter("username").getBytes("ISO-8859-1"),"UTF-8");
			password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"UTF-8");
			role = new String(request.getParameter("role").getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		
		if (nachname.equals("")
				|| vorname.equals("")
				|| username.equals("")
				|| password.equals("")
				|| role.equals("")){
			
			setApplicationMessage(s, getMessageProperty("angabenNichtKomplett"));
			return getForwardProperty("createUser");
		}
		else{
			saveObjectinSession(request, "createUserFormBean", new CreateUserFormBean(nachname, vorname, username, password, role));
			return getForwardProperty("createUserBestaetigung");
			
		}
	}
}
